package com.jsoft.service;

import com.jsoft.dto.PlaceDto;
import com.jsoft.manager.PlaceManager;
import com.jsoft.manager.SectorManager;
import com.jsoft.model.PlaceDao;
import com.jsoft.model.SectorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Date: 22.08.13
 * Time: 18:25
 */

@Service
public class PlaceServiceImpl implements PlaceService {
    @Autowired
    private PlaceManager placeManager;
    @Autowired
    private SectorManager sectorManager;

    @Override
    @Transactional(readOnly = true)
    public List<PlaceDto> getPlaceList() {
        List<PlaceDao> placeDaoList = placeManager.getAllList();
        List<PlaceDto> placeDtoList = new ArrayList<PlaceDto>();
        for (PlaceDao dao : placeDaoList) {
            placeDtoList.add(dao.wrapPlaceDto());
        }
        return placeDtoList;
    }

    @Override
    public List<PlaceDto> getPlaceListBySectorId(Integer sectorId) {
        SectorDao dao = sectorManager.getById(sectorId);
        List<PlaceDao> placeDaoList = dao.getPlaceList();
        List<PlaceDto> placeDtoList = new ArrayList<PlaceDto>();
        for (PlaceDao place : placeDaoList) {
            placeDtoList.add(place.wrapPlaceDto());
        }
        return placeDtoList;
    }
}
